#region [file: ClienteDAL.cs, author: Lucas Bittencourt]
// File:    ClienteDAL.cs
// Author:  Lucas Bittencourt
// Created: terça-feira, 25 de outubro de 2011 09:26:29
// Purpose: Defines dao implementation class for class Cliente
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IClienteDAL interface
   /// </summary>
    public partial class ClienteDAL : NHibernateDALBase, IClienteDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Cliente
      /// </summary>     
      public List<Cliente> GetClienteList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Cliente)));
      }
      
      /// <summary>
      /// Get the instances of Cliente from index firstResult to index maxResult
      /// </summary>
      public List<Cliente> GetClienteList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Cliente), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Cliente according its primary key instance.
      /// </summary>
      public Cliente Load(ClientePK clientePK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "CliIdCliente" };
         object[] values = new object[] { clientePK.CliIdCliente };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Cliente), cs);
         return (((list != null) && (list.Count > 0)) ? (Cliente)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Cliente according its example instance.
      /// </summary>
      public List<Cliente> QueryByExample(Cliente cliente)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Cliente), cliente));
      }

      /// <summary>
      /// Query the instances of Cliente according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Cliente> QueryByExample(Cliente cliente, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Cliente), cliente, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Cliente
      /// </summary>
      public void Insert(Cliente clienteObject)
      {
         base.Save(clienteObject);
      }
      
      /// <summary>
      /// Update the instances of Cliente
      /// </summary>
      public void Update(Cliente clienteObject)
      {
         base.Update(clienteObject);
      }
      
      /// <summary>
      /// Delete the instances of Cliente
      /// </summary>
      public void Delete(Cliente clienteObject)
      {
         base.Delete(clienteObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Cliente according to its attribute cliChAtivo
      /// </summary>
      public List<Cliente> FindByCliChAtivo(bool cliChAtivo) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CliChAtivo", cliChAtivo));
         return ConvertToGenericList(base.FindByCriterions(typeof(Cliente), cs));
      }
      
      /// <summary>
      /// Find the instances of Cliente according to its attribute cliChAtivo, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Cliente> FindByCliChAtivo(bool cliChAtivo, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("CliChAtivo", cliChAtivo));
         return ConvertToGenericList(base.FindByCriterions(typeof(Cliente), cs, firstResult, maxResult));
      }
      /// <summary>
      /// Find <Code>Cliente</Code> instances by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <returns>Cliente instance list</returns>
      public List<Cliente> FindByPessoa(Pessoa pessoa)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs));
      }
      
      
      /// <summary>
      /// Find <Code>Cliente</Code> instances  instances in range firstResult, maxResult by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Cliente instance list</returns>
      public List<Cliente> FindByPessoa(Pessoa pessoa, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));}

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Cliente> ConvertToGenericList(IList clientes)
      {
         List<Cliente> clienteList = new List<Cliente>();
         foreach (Cliente cliente in clientes)
         {
             clienteList.Add(cliente);
         }
         return clienteList;
      }      
   }
}